import { createStore } from 'vuex'
import api from "../api/api";
export default createStore({
    state: {
        tagsList: [],
        collapse: false,
    },
    mutations: {
        delTagsItem(state, data) {
            state
                .tagsList
                .splice(data.index, 1);
        },
        setTagsItem(state, data) {
            state
                .tagsList
                .push(data)
        },
        clearTags(state) {
            state.tagsList = []
        },
        closeTagsOther(state, data) {
            state.tagsList = data;
        },
        closeCurrentTag(state, data) {
            for (let i = 0, len = state.tagsList.length; i < len; i++) {
                const item = state.tagsList[i];
                if (item.path === data.$route.fullPath) {
                    if (i < len - 1) {
                        data
                            .$router
                            .push(state.tagsList[i + 1].path);
                    } else if (i > 0) {
                        data
                            .$router
                            .push(state.tagsList[i - 1].path);
                    } else {
                        data
                            .$router
                            .push("/");
                    }
                    state
                        .tagsList
                        .splice(i, 1);
                    break;
                }
            }
        },
        // 侧边栏折叠
        handleCollapse(state, data) {
            state.collapse = data;
        },

    },
    actions: {
        //判断是否展示区块链
        isBlockchain() {
            return new Promise(function (resolve, reject) {
                api
                    .getListAPI("auth/client/account/getCurrentDetail", {})
                    .then((res) => {
                        if (res.data.code == 1) {
                            if (res.data.data.isChain == 0) {
                                resolve(false)
                            } else {
                                resolve(true)
                            }
                        } else {
                            resolve(true)
                        }

                    })
                    .catch((err) => {

                    });
            })

        },
        getplatformName() {
            return new Promise(function (resolve, reject) {
                // type 5为客户端
                api
                    .getListAPI("auth/platform/getDetail/5", {})
                    .then((res) => {
                        if (res.data.code == 1) {
                            resolve(res.data.data.platformName);
                            localStorage.setItem("platformName", res.data.data.platformName);
                        }
                    })
                    .catch((err) => { });
            })
        }
    },
    modules: {}
})